﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace NerdDinner.Controllers.components
{
    public class PaginatedList<T> : List<T>
    {
        public int PageIndex;
        public int PageSize;
        public int TotalCount;
        public int TotalPages;
        public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = source.Count();
            TotalPages = (int) Math.Ceiling(TotalCount/(double)pageSize);
            this.AddRange(source.Skip(pageIndex * pageSize).Take(pageSize));
        }

        public bool HasPreviousPage 
        { 
            get { return (PageIndex > 0); }
        }
        public bool HasMorePage
        {
            get { return (PageIndex < TotalPages); }
        }
    }
}